<template>
	<view class="content">
		<view class="item f-c-b">
			<view class="">店铺名称</view>
			<input v-model='form.shopname' type="text" placeholder="请输入店铺名称" placeholder-class="placCls" />
		</view>
		<view class="item f-c-b">
			<view class="">身份证号</view>
			<input v-model='form.idnumber' type="text" placeholder="请输入身份证号" placeholder-class="placCls" />
		</view>
		<view class="item f-c-b">
			<view class="">身份证姓名</view>
			<input v-model='form.idname' type="text" placeholder="请输入身份证姓名" placeholder-class="placCls" />
		</view>
		<view class="item">
			<view class="">上传营业执照</view>
			<view class="f">
				<view class="imgClass">
					<image class="imgListClass" v-for="(item,index) in imgList" :src="$u.baseUrl+item"
						mode="aspectFill"></image>
				</view>
				<view class="item_img f-c-c" v-show="imgList.length<1">
					<image @click="toUploadImg" src="../../static/index-cate/icon_jh.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<view @click="toSubmit" class="btn f-c-c">提交</view>
		<u-toast ref="uToast" />
	</view>

</template>

<script>
	import uploadImg from '../../utils/uploadImg/index.js'
	export default {
		data() {
			return {
				imgList: [],
				form:{
					shopname:'',
					idname:'',
					idnumber:''
				}
			}
		},
		methods: {
			async toUploadImg() {
				/* 1. 上传图片，获得转换好的地址 */
				const res = await uploadImg(this.$u.api.fileUpLoad, 1)
				this.imgList=res
			},
			async toSubmit() {
				// this.$refs.uToast.show({
				// 	title: '提交成功',
				// 	position: 'bottom'
				// })
				if(!this.$u.test.idCard(this.form.idnumber)){
					this.$u.toast('请输入正确的身份证号！')
					return
				}
				if(this.form.idname==''){
					this.$u.toast('请输入身份证姓名！')
					return
				}
				if(this.form.shopname==''){
					this.$u.toast('请输入店铺名称！')
					return
				}
				if(this.imgList.length<1){
					this.$u.toast('请上传营业执照！！')
					return
				}
				const {success,msg}=await this.$u.api.addBAttestation({
					bimg:this.imgList[0],
					consumer:this.vuex_user.id,
					idname:this.form.idname,
					idnumber:this.form.idnumber,
					shopname:this.form.shopname,
				})
				if(!success){
					this.$u.toast(msg)
				}
				this.$refs.uToast.show({
					title:msg,
					position: 'bottom'
				})
				setInterval(()=>{
										 this.$back(1)
				},1000)
				
			}
		}
	}
</script>

<style>
	.content {
		height: 100vh;
		background-color: #F6F6F6;
	}

	.item {
		background-color: #FFFFFF;
		padding: 30rpx 20rpx;
		margin: 2rpx 0;
	}

	.item input {
		text-align: right;
	}

	.placCls {
		font-size: 30rpx;
		color: #999999;
	}

	.item_img {
		width: 160rpx;
		height: 160rpx;
		background-color: #EEEEEE;
		margin-top: 30rpx;
	}

	.item_img image {
		width: 62rpx;
	}

	.imgListClass {
		height: 160rpx;
		width: 160rpx;
		margin-right: 20rpx;
	}

	.imgClass {
		height: 160rpx;
		margin-top: 30rpx;
	}

	.btn {
		background-color: #FF8710;
		color: #FFFFFF;
		margin: 500rpx 40rpx;
		padding: 20rpx;
		border-radius: 40rpx;
	}
</style>
